import '../index.scss';
import XHeader from 'vux/src/components/x-header/index.vue'
import Swiper from 'vux/src/components/swiper/swiper.vue'
import SwiperItem from 'vux/src/components/swiper/swiper-item.vue'
import XButton from 'vux/src/components/x-button/index.vue'
import Flexbox from 'vux/src/components/flexbox/flexbox.vue'
import FlexboxItem from 'vux/src/components/flexbox/flexbox-item.vue'
import Popup from 'vux/src/components/popup/index.vue'
import Group from 'vux/src/components/group/index.vue'
import Cell from 'vux/src/components/cell/index.vue'
import Checker from 'vux/src/components/checker/checker.vue'
import Divider from 'vux/src/components/divider/index'
import CheckerItem from 'vux/src/components/checker/checker-item.vue'
import XInput from 'vux/src/components/x-input/index.vue'
import XTextarea from 'vux/src/components/x-textarea/index.vue'
import Alert from 'vux/src/components/alert/index.vue'
import Checklist from 'vux/src/components/checklist/index.vue'
import Tab  from 'vux/src/components/tab/tab'
import TabItem  from 'vux/src/components/tab/tab-item'
import XProgress from 'vux/src/components/x-progress/index'
import Box from 'vux/src/components/box/index'
import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import TransferDom from "vux/src/directives/transfer-dom/index";
import VueQr from "vue-qr";


export default {
  name: 'togetherShop',
  directives: {
    TransferDom
  },
  // ready () {
  //   setInterval(this.update2, 2000)
  // },
  components: {
    // Schart,
    // XCircle,
    // Range,
    // Icon
    Tab,
    TabItem,
    XProgress,
    Box,
    XButton,
    Flexbox,
    FlexboxItem,
    Checker,
    TransferDom,
    CheckerItem,
    Divider,
    Group,
    Cell,
    Popup,
    XInput,
    XTextarea,
    Checklist,
    Alert,
    VueQr,


  },
  data() {
    return {
      firstWord:'',
      endWord:'',
      showj:false,
      textMoney: '',
      together_id:'',
      personalArr: [],
      termArr: [],
      companyArr: [],
      tolist: [],
      messageText: '',


      index: 0,
      // 信息反馈是否有红点  为''的时候没有  为' '的时候有
      isXinxi: ' ',
      percent: 60,
      show: false,
      demo: 1,
      isM: '募捐中',
      userId: '',
      eventType: '',
      feedBack: [],


      name: '',
      mobile: '',
      IDNum: '',
      liuyan: '',
      ifShowtt: false,
      address: '',
      dotScale: 1,
      logoMargin: 5,
      margin: 0,
      logoCornerRadius: 4,
      item: 'item',
      textMoney: '',
      siteName:'支教团队',
      checkOK: true,
      isA: true,
      threshold: 50,
      minmovingdistance: 30,
      // 项目id
      event_id: '',
      // 显示哪一个模块
      pageNoOther: 1,
      pageNoJuankuan: 1,
      pageSize: 20,
      eventAll: {},
      eventOther: [],
      eventJuankuan: [],
      lookMore: '查看更多',
      lookMoreJuankuans: '查看更多',
      leaveMessage: [],
      pageNoLeave: 1,
      isVolunteer: false,
      ifselected: false,
      configSuccess: false,
      showArea: 1,
      showLogo: false,
      showDetail: false,
      showTab: false,
      showHistory: false,
	  donateClass:'donateDisabled',
      obj: {
        eventName: "",
		    eventStatus: 1,
        eventPicUrl: "",
        raiseMoney :"" ,
        day :"",
        storeCount :"",
        stores : [
          {
            storeId: "",
            storeName:"",
            storeArea:null,
            money :'',
            schedule :null,
            countPeople :''
          }
        ],
        activityResults :[
          {
            activityId:"",
            title:"",
            content:"",
            picture :"",
            createDate:""
          }
        ]
      },
    }
  },
  mounted() {
    let openid = sessionStorage.getItem("openid")
    if (openid == null || openid == '' || openid == 'undefined') {
      sessionStorage.setItem('openid', this.$route.query.openId)
      sessionStorage.setItem('userId', this.$route.query.userId)
      sessionStorage.setItem('wxAvatar', this.$route.query.wxAvatar)
      sessionStorage.setItem('nickName', this.$route.query.nickName)
      sessionStorage.setItem('event_id', this.$route.query.event_id)
      sessionStorage.setItem('choice',this.$route.query.choice)

      // console.log(window.sessionStorage.getItem('openid'))
      let openid = sessionStorage.getItem("openid")
      if (openid == null || openid == '' || openid == 'undefined') {
        // alert('进行页面的跳转')
        window.location.href = 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=3&event_id=' + this.$route.query.event_id
      }
    }
    this.userId = window.sessionStorage.getItem('userId')
    this.event_id = this.$route.query.event_id;
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path, this.event_id)
    }
    if (this.$route.query.openId) {
      window.location.reload()
    }
    http.post(CONSTANT.EVENT_VIEW_TH, {event_id: this.event_id,area:0}, (res) => {
      this.obj = res.obj;
      this.obj.eventPicUrl = this.imageUrl.imageUrl + this.obj.eventPicUrl;
      this.firstWord = this.obj.eventAbstract.substring(0,1)
      this.endWord = this.obj.eventAbstract.substring(1)
      if (res.obj.eventStatus == 1) {
        this.donateClass = 'donate'
      }
      if (this.event_id == '2fc92c2a95c14c6698f123dd34f5f248') {
        this.showLogo = true
        this.showDetail = true
        this.showTab = true
        this.showHistory = true
      }
    //alert(this.obj.stores.length)
    this.$emit('ShareAppMessage', this.obj.eventName, '【亲青筹】' + this.obj.eventAbstract, 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=3&event_id=' + this.event_id, this.obj.eventPicUrl)
  })
  },
  methods: {
    onItemClick (value, disabled) {
      console.log(value, disabled)
      if (!this.disabled) {
        this.showPopup = false
      }
    },
    comeback() {
      // 返回上一页
      window.history.go(-1)
    },
    witchShow (e) {
      if (e == 0) {
        this.showArea = 1
      } else {
        this.showArea = 0
      }
      http.post(CONSTANT.GET_STORES, {event_id: this.event_id,area:e}, (res) => {
        this.obj.stores = res.obj.stores;
        if (this.obj.eventStatus != 1) {
          this.donateClass = 'donateDisabled'
        }
      })
    },
    // update2 () {
    //   const colorMap = ['#3FC7FA', '#85D262', '#FE8C6A']
    //   this.percent2 = parseInt(Math.random() * 100, 10)
    //   this.strokeColor2 = colorMap[parseInt(Math.random() * 3, 10)]
    // }
    onItemClick (index) {
      console.log('on item click:', index)
    },
    wantJuank () {
      // 我要捐款
      this.show = true
    },
    isShow () {
      // 弹出框关闭按钮
      this.show = false
    },
    keyups () {
      this.demo = this.textMoney
      this.ifselected = true
    },
    blurs () {
      this.ifselected = false
    },
    checkerWitch () {
      // 选择捐款金额
      // console.log(this.demo)
    },
    checkOk () {
      // 是否同意用户协议
      // console.log(this.checkOK)
    },
    textMoneyChange () {
      // console.log('hh')
    },
    goreport () {
      this.$router.push({path: '/report'})
    },
    godonation () {
      this.$router.push({path: '/donation'})
    },
    govolunteer () {
      this.$router.push({
        path: '/volunteer',
        query: {volunteerLocal: this.eventAll.volunteerLocal, volunteerTime: this.eventAll.volunteerTime}
      })
    },
    isShow () {
      // 弹出框关闭按钮
      this.showj = false
    },
    primaryshow (t) {
		if (this.obj.eventStatus == 1) {
			 this.showj = true
			 this.together_id = t
		}
    },
    goDetail () {
      var url = encodeURIComponent("http://wx.5dtianheng.com/WX/OutLink?ID=4");
      location.href = "http://www.qqchou.org/a/wxinterface/toShare?url="+url
    },
    primary () {
		let _this = this
		if (_this.obj.eventStatus == 1) {
		  let num = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
		  if (_this.demo == '') {
			alert('请选择捐款金额!')
		  } else if (!num.test(_this.demo)) {
			alert('请输入正确的金额数!（提示：只能是数字或者精确到两位小数）')
		  } else if (_this.demo == 0 || _this.demo == '0.00') {
			alert('请输入正确的金额数!（提示：只能是数字或者精确到两位小数）')
		  } else if (this.checkOK == false) {
			alert('请同意并接受\n《亲青筹用户协议》！')
		  } else {
			// window.location.href = 'http://qqc.hztangong.com/a/wxinterface/payment?' + 'witchOne=geren&userId=' +
			//   this.userId + '&money=' + this.demo + '&eventId=' + this.event_id
			this.$router.push({path: '/payment', query: {witchOne: 'geren', money: this.demo, together_id:this.together_id,is_together:3,event_id:this.event_id}})
		  }
		}
    },
    goDetails (e) {
      location.href = "https://mp.weixin.qq.com/mp/homepage?__biz=MzI2NTgxMjczOQ==&hid=3&sn=b461692372d1c90f5f90ba003ab91660&scene=18&uin=&key=&devicetype=Windows+10&version=6206021b&lang=zh_CN&ascene=1&winzoom=1";
      //this.$router.push({path: '/guozhenDetails', query: {id: e}})
    },
    wantJuank () {
      this.$router.push({path: '/userhome'})
    }
  }
}
